package com.smart.thrift.config.server;

import com.smart.thrift.model.server.IThriftServer;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.CollectionUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingDeque;

@Getter
@Setter
public class ThriftServerGroup {

    /**
     * 对外服务名
     */
    private String serverName;

    private Queue<IThriftServer> servers = new LinkedBlockingDeque<>();

    public ThriftServerGroup(IThriftServer... servers) {
        if (Objects.isNull(servers) || servers.length == 0) {
            return;
        }

        this.servers.addAll(Arrays.asList(servers));
    }

    public ThriftServerGroup(List<IThriftServer> servers) {
        if (CollectionUtils.isEmpty(servers)) {
            return;
        }

        this.servers.clear();
        this.servers.addAll(servers);
    }

    public String getServerName() {
        return serverName;
    }

    public void setServerName(String serverName) {
        this.serverName = serverName;
    }
}
